<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改角色权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css">
    <script src="__STATIC__/lib/layui/layui.js" ></script>
    <script src="__STATIC__/admin/js/jquery-3.3.1.js"></script>
    <link id="layuicss-layuiAdmin" rel="stylesheet" href="__STATIC__/admin/css/admin.css" media="all">
</head>
<body layadmin-themealias="default" class="layui-layout-body" style="">
<div id="LAY_app" class="layadmin-tabspage-none">
    <div class="layui-layout layui-layout-admin">
        <!--头部文件-->
        {include file="common/header"/}
        <!--左侧导航栏-->
        {include file="common/left"/}

        <!-- 主体内容 -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <div class="layui-card layadmin-header">
                    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
                        <a lay-href="{:url('index/index')}">主页</a><span lay-separator="">/</span>
                        <a href="{:url('lst')}"><cite>角色列表</cite></a><span lay-separator="">/</span>
                        <a><cite>修改角色权限</cite></a>
                    </div>
                </div>

                <div class="layui-fluid">
                    <div class="layui-card" style="padding-bottom: 20px;padding-top: 20px;">
                        <form class="layui-form" method="post">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">角色名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="id" hidden="hidden"  value="{$cur_role['id']}">
                                        <input type="tel" name="name" lay-verify="required|name" autocomplete="off" class="layui-input" value="{$cur_role['name']}">
                                    </div>
                                </div>
                            </div>
                            <div style="width: 90%;margin-left: 6.5%;margin-bottom: 30px;">
                                <div style="font-size: 20px;margin-bottom: 15px;">选择角色权限</div>

                                <div class="layui-collapse">

                                    {foreach $powerL as $key=>$value}
                                    <div class="layui-colla-item">
                                        <h2 class="layui-colla-title">{$value['name']}</h2>
                                        <div class="layui-colla-content layui-show ">
                                            <div class="layui-form-item">
                                                {foreach($value['son'] as $k=>$v)}
                                                <input type="checkbox" class="power" name="power" powerid="{$v['id']}" title="{$v['name']}"  <?php if( in_array($v['id'],$cur_power)){ ?> checked <?php ;} ?>  />
                                                {/foreach}
                                            </div>
                                        </div>
                                    </div>
                                    {/foreach}

                                </div>
                            </div>



                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="sub">提交</button>
                                    <a class="layui-btn layui-btn-primary" href="{:url('lst')}">返回</a>
                                </div>
                            </div>

                        </form>
                    </div>


                </div>

            </div>
        </div>


    </div>
</div>


</body>

<script>
    $(function () {
        layui.use(['form','element'],function (data) {
            var form=layui.form; var layer=layui.layer;element=layui.element;
            form.render();  //下拉框弹出
            $('.open').click(function () {
                $(this).toggleClass('layui-nav-itemed');
            });
            form.on("submit(sub)",function (data) {
                //循环得到复选框的值
                var po='';
                $('.power:checked').each(function () {
                        po +=','+$(this).attr('powerid');
                    }
                );
                data.field.power=po;
                //提交数据
                $.post("{:url('role/edit')}",data.field,function (res) {
                    if(res.code==1){
                        layer.msg(res.msg,{icon:1,time:1800});
                        setTimeout(function () {
                            window.location.href="{:url('lst')}";
                        },1500);
                    }else {
                        layer.msg(res.msg,{icon:5,time:1800});
                    }

                    return false;
                });

                return false;
            });

        });
    });



</script>


</html>